/* interface IPerson1 {
  name: string
  age: number
  sex: string
}

interface IPerson2 {
  name: number
  age: number
  sex: string
} */

/* interface IPerson<T> {
  name: T
  age: number
  sex: string
}

// 泛型接口调用的时候不能省略泛型参数
const p1: IPerson<string> = {
  name: 'xxx',
  age: 18,
  sex: 'man',
}
const p2: IPerson<number> = {
  name: 1682,
  age: 18,
  sex: 'man',
} */

/* interface IdFunc<T> {
  id: (value: T) => T
  ids: () => T[]
}

let string = 'abc'
const o: IdFunc<string> = {
  id: (v: string) => string,
  ids: () => ['a', 'b'],
} */

// const arr1: string[] = ['a', 'b', 'c']
// 泛型的定义方式
// const arr2: Array<string> = ['a', 'b', 'c']

// 模拟 Array<string> 定义数组的写法
interface IArray<T> {
  // key: T
  // 任意的索引是 number 类型，值是 T 类型
  [key: number]: T
}

const arr2: IArray<string> = ['a', 'b', 'c']
const arr3: IArray<string | number> = ['a', 'b', 'c', 1]

// arr2[0]
// arr2[1]

const age = '18'
const obj = {
  [age]: 19,
}
console.log(obj)

export {}
